package com.acme.service.security.impl;

import javax.transaction.Transactional;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.core.userdetails.UserDetails;
import org.springframework.security.core.userdetails.UserDetailsService;
import org.springframework.security.core.userdetails.UsernameNotFoundException;
import org.springframework.stereotype.Service;

import com.acme.dao.security.DBUserDAO;
import com.acme.entity.User;
import com.acme.entity.security.DBUserDetails;

@Service("authService")
@Transactional
public class DBUserDetailsServiceImpl implements UserDetailsService
	{
	@Autowired
	private DBUserDAO dbUserDAO;
	
	
	@Override
	public UserDetails loadUserByUsername(String username)
			throws UsernameNotFoundException
		{
		User user = dbUserDAO.getUserByUsername(username);
		if(user == null) throw new UsernameNotFoundException("Username not found!");
		DBUserDetails userDetails = new DBUserDetails();
		userDetails.setDbUserDAO(dbUserDAO);
		userDetails.setUser(user);
		return userDetails;
		}
	}
